package camel.dsrawat.examples;

import javax.jms.ConnectionFactory;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;

public class JMSRead extends RouteBuilder {

	@Override
	public void configure() throws Exception {
		from("jms:queue:TestQueue").
		process(new Processor() {
			public void process(Exchange arg0) throws Exception {
				System.out.println("######" + arg0.getIn().getHeaders());
				System.out.println(arg0.getIn().getBody());
			}
		});
		//to("log:System.out.println");
	}

	public static void main(String[] args) throws Exception {

		CamelContext ctx = new DefaultCamelContext();

		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
		ctx.addComponent("jms",	JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));

		ctx.addRoutes(new JMSRead());
		ctx.start();

		Thread.sleep(10000);
	}

}
